package com.hgxd.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hgxd.entity.pojo.Slave;
import com.hgxd.mapper.SlaveMapper;
import com.hgxd.service.ISlaveService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 从机列表 服务实现类
 * </p>
 *
 * @author fsd
 * @since 2023-10-18
 */
@Service("SlaveServiceImpl")
public class SlaveServiceImpl extends ServiceImpl<SlaveMapper, Slave> implements ISlaveService {

    @Resource
    private SlaveMapper slaveMapper;

    @Override
    public List<Slave> getSlavesByOrganizationId(Integer organizationId) {
        QueryWrapper<Slave> slaveQueryWrapper = new QueryWrapper<>();
        slaveQueryWrapper.in("organization_id",organizationId);
        return slaveMapper.selectList(slaveQueryWrapper);
    }

    @Override
    public List<Slave> getNewDataByOrganizationName(String organizationName) {
        return slaveMapper.getNewDataByOrganizationName(organizationName);
    }

    @Override
    public List<String> getAllCntrNo() {
        return slaveMapper.getAllCntrNo();
    }

    @Override
    public List<Slave> getSlavesByCntrNo(String cntrNo) {
        LambdaQueryWrapper<Slave> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(!StrUtil.isBlank(cntrNo),Slave::getCntrNo,cntrNo);
        return slaveMapper.selectList(queryWrapper);
    }
}
